<extend name="./public/frame.html"/>
<block name="content">
    <div style="width: 70%">
        <eq name="type" value="refund">
            <form  class="layui-form" lay-filter="demo">
                <input type="text" name="id" value="{$info['id']}" hidden/>
                <input type="text" name="handle_type" id="type" value="2" hidden/>
                <table class="layui-table">
                    <volist name="fields" id="field">
                        <tr>
                            <td>{$field}</td>
                            <if condition="$key=='is_handle'">
                                <php>$color = $info[$key]==2?'red':'deepskyblue'</php>
                                <td style="color: {$color}" colspan="2">
                                    <eq name="info[$key]" value="1">
                                        已退款
                                        <else/>
                                        未处理
                                    </eq>
                                </td>
                                <elseif condition="$key=='fact_money'" />
                                <td>
                                    <input type="text" class="layui-input" name="fact_money"  style="display: inline-block;width: 80%" onchange="tip(this)"
                                           placeholder="实际退款金额不写时，系统将自动计算退款金额" value="{$info['fact_money_c']}">
                                    <span style="display: inline-block">元</span>
                                </td>
                                <td style="color:red;">实际退款金额不写时，系统将自动计算退款金额</td>
                                <elseif condition="$key=='force_cancel_rate'"/>
                                <td>
                                    <notempty name="info[$key]">
                                        {$info[$key]}%
                                        <else/>
                                        0
                                    </notempty>
                                </td>
                                <else/>
                                <td colspan="2">{$info[$key]}</td>
                            </if>
                        </tr>
                    </volist>
                    <tr>
                        <td>备注</td>
                        <td colspan="2">
                            <textarea placeholder="备注(用于对退款说明,可不写)" name="remark" class="layui-textarea" id="remark"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <button class="layui-btn" lay-submit lay-filter="submit">提交</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </td>
                    </tr>
                </table>
            </form>
            <div class="fadeBg"></div>
            <div class="fadeCont"style="width: 20%;left: 40%;top: 30%">
                <div class="fadeBox upload">
                    <img src="__WEB__/images/uploading.gif" style="width: 30%;height: auto">
                    <p style="font-size: 12px;margin-bottom: 3px;">处理中……</p>
                </div>
            </div>
            <else/>
            <div class="layui-collapse" lay-filter="refund">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title" data-v="driver">退款申请详情</h2>
                    <div class="layui-colla-content layui-show">
                        <table class="layui-table">
                            <volist name="fields" id="field">
                                <notempty name="info[$key]">
                                    <tr>
                                        <td>{$field}</td>
                                        <eq name="key" value="is_handle">
                                            <php>$color = $info[$key]==2?'red':'deepskyblue'</php>
                                            <td style="color: {$color}">
                                                <eq name="info[$key]" value="1">
                                                    已退款
                                                    <else/>
                                                    未处理
                                                </eq>
                                            </td>
                                            <else/>
                                            <td>{$info[$key]}</td>
                                        </eq>
                                    </tr>
                                </notempty>
                            </volist>
                        </table>
                    </div>
                </div>
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title"  data-v="user" data-value="{$info['member_id']}" data-act="no">用户余额</h2>
                    <div class="layui-colla-content">
                        用户当前的余额： {$user_wallet_info['wallet_money']} 。赠送余额：{$user_wallet_info['return_money']}
                    </div>
                </div>
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title"  data-v="order" data-value="{$info['common_id']}" data-act="no">订单详情</h2>
                    <div class="layui-colla-content">

                    </div>
                </div>
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title"  data-v="pay" data-value="{$info['log_id']}" data-act="no">订单支付信息</h2>
                    <div class="layui-colla-content">

                    </div>
                </div>
            </div>
        </eq>
    </div>
    <eq name="type" value="refund">
        <script type="application/javascript">
            var fact_c = {$info['fact_money_c']};
            layui.use(['form'], function(){
                var fadeBg = $('.fadeBg');
                var tip = $('.fadeCont .upload');
                var txt = $('.fadeCont');
                var refund_sn = "{$info['refund_sn']}",order_sn = "{$info['order_sn']}";//用于日志
                var form = layui.form;
                form.on('submit(submit)', function(data){
                    var id = data.field.id;
                    var fact_money = data.field.fact_money;
                    var remark = data.field.remark;
                    var type = data.field.handle_type;
                    if(fact_money&&isNumber(fact_money)&& isIntNum(fact_money)){
                        layer.alert('实际退款金额格式错误');
                        return false;
                    }
                    fadeBg.show();
                    tip.show();
                    txt.show();
                    $.post('/admin/inter_refund/refund',
                        {id:id,fact_money:fact_money,remark:remark,type:type,fact_c:fact_c,refund_sn:refund_sn,order_sn:order_sn},
                        function (res) {
                            fadeBg.hide();
                            tip.hide();
                            txt.hide();
                            switch (res['status']){
                                case 1:
                                    layer.alert(res['msg'],{icon:1},function () {
                                        window.open(res['url'],'_self');
                                    });
                                    break;
                                case 2:
                                    layer.alert(res['msg'],{icon:2},function (index) {
                                        $("input[name='fact_money']").val(res['data']);
                                        $('#type').val(2);
                                        layer.close(index);
                                    });
                                    break;
                                default:
                                    layer.alert(res['msg'],{icon: 5});
                                    break;
                            }
                        },'json');
                    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
                });
            });
            function isNumber(val){
                var regPos = /^\d+(\.\d+)?$/; //非负浮点数
                // var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数
                if(regPos.test(val)){
                    return true;
                }else{
                    return false;
                }

            }
            function isIntNum(val){
                var regPos = / ^\d+$/; // 非负整数
                // var regNeg = /^\-[1-9][0-9]*$/; // 负整数
                if(regPos.test(val)){
                    return true;
                }else{
                    return false;
                }
            }
            function tip(obj) {
                var s = confirm('确认需要修改么，这将不会自动计算，且存在不扣除手续费的风险');
                var type = $('#type');
                if(s){
                    type.val(1);
                }else{
                    $(obj).val(fact_c);
                    type.val(2);
                }
            }
        </script>
        <else/>
        <script>
            layui.use(['layer','element'], function(){
                var layer = layui.layer;
                var element = layui.element;
                var $ = layui.jquery;
                element.on('collapse(refund)', function(data){
                    var title = data.title;
                    switch (title.data('v')){
                        case 'order':
                            if(title.data('act')=='no'){
                                title.data('act','yes');
                                $.get('/admin/inter_order/detail',{common_id:title.data('value'),from:'refund'},function (res) {
                                    switch (res['status']){
                                        case 1:
                                            data.content.html(res['html']);
                                            break;
                                        default:
                                            data.content.html(res['msg']);
                                            break;
                                    }
                                },'json')
                            }
                            break;
                        case 'pay':
                            if(title.data('act')=='no'){
                                title.data('act','yes');
                                $.get('/admin/inter_pay_log/detail',{id:title.data('value'),from:'refund'},function (res) {
                                    switch (res['status']){
                                        case 1:
                                            data.content.html(res['html']);
                                            break;
                                        default:
                                            data.content.html(res['msg']);
                                            break;
                                    }
                                },'json')
                            }
                            break;
                        default:
                            break;
                    }
                });
            });
        </script>
    </eq>
</block>